#!F:\Python
#code=utf-8

from skydbobject import *
from sqlalchemy import *
from sqlalchemy.orm import *
dbengine = create_engine(g_DBConnectionStr, echo = True)
skyUserInfoTable = Table('skyUserInfo', dbengine, autoload = True)
skyUserRelationTable = Table('skyUserRelation', dbengine, autoload = True)
skySceneTable = Table('skyScene', dbengine, autoload = True)

mapper(skyUserRelationObj, skyUserRelationTable)
mapper(skySceneObj, skySceneTable)
mapper(skyUserInfoObj, skyUserInfoTable )
#, properties = {'sense' : relation(skySceneObj)}
def fillUserData():
    obj = skyUserInfoObj()
    obj.accounts = 'xuhong'
    obj.password = '123'
    obj.nickName = "fancyboyxh"
    obj.officePhoneNum = '28973679'
    obj.homePhoneNum = '2811111'
    obj.mobileNumber = '21323310'
    obj.email = "fancyboyxh@gmail.com"
    obj.address = "shenzheng HuaWei"
    obj.myUrl = "http://www.googlc.com"
    obj.photo = "d:/mypp"
    obj.imTool = None
    obj.remark = 'This is my Information, please securit it'
    obj.sceneID = 1
    sess = create_session()
    sess.save(obj)
    sess.flush()
    
def fillSenseData():
    objsen = skySceneObj()
    objsen.userID = 1
    objsen.sceneID = 1
    objsen.phoneIndex = 1
    objsen.scenseName = 'Defalut'
    objsen.touchFreqency = 1
    objsen1 = skySceneObj()
    objsen1.userID = 2
    objsen1.sceneID = 2
    objsen1.phoneIndex = 2
    objsen1.scenseName = 'Office'
    objsen1.touchFreqency = 10
    sess1 = create_session()
    sess1.save(objsen)
    sess1.save(objsen1)
    sess1.flush()
    
# fillUserData() ###############################################################
# fillSenseData() ##############################################################
session = create_session()
session._set_echo_uow(value=True)
reslut = session.query(skyUserInfoObj).select(skyUserInfoObj.c.accounts == 'xuhong')
session.flush()
print reslut.__class__.__name__
for i in reslut :
    print i
# print reslut #################################################################


